﻿
jQuery(document).ready(function () {
    checkMonthlyAlert();
});

function checkMonthlyAlert() {

   if ($("#web_mo_alert_email").val() == '') {
        $("#chkemail").attr('checked', false);
        $("#chkNoAlert").attr('checked', true);
    }
    else {
        $("#chkemail").attr('checked', true);
        $("#chkNoAlert").attr('checked', false);
    }
}


$("#chkemail").live("click", function (e) {

    if ($(this).is(':checked')) {

        $("#chkNoAlert").attr('checked', false);
    }
    else {
        $("#chkNoAlert").attr('checked', true);
        $("#web_mo_alert_email").val('');
    }

});

$("#chkNoAlert").live("click", function (e) {

    if ($(this).is(':checked')) {
        
        $("#web_mo_alert_email").val('');
        $("#chkemail").attr('checked', false);
    }
    else {
        $("#chkemail").attr('checked', true);
    }
});

$("#web_mo_alert_email").live("keypress", function (e) {

    //If user starts to type in email textbox,then radio button for “Email” becomes active
    $("#chkemail").attr('checked', true);
    $("#chkNoAlert").attr('checked', false);
});


$('#web_mo_alert_email').live("keyup", function (e) {

    if (e.which == 8 && this.value.length == 0) {
        $("#chkemail").attr('checked', false);
        $("#chkNoAlert").attr('checked', true);

        $("#web_mo_alert_email").val('');
    }
});

$("#web_mo_alert_email").live("blur", function (e) {

    //check that email format  is correct
    if ($(this).val() != '') {
        var returnValue = isValidEmailAddress($(this).val());
        if (returnValue == false) {
            alert("Email address is not in the proper format for a valid email address.");
        }
       
    }
});

$("#finishweb").click(function () {
    if ($("#chkemail").is(':checked') && $("#web_mo_alert_email").val() == '') {
        alert("You must enter the email.");
        return false;
    }
    else {

        $("#UpdateWebMonthlyReminderForm").submit();
    }
});




